import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [{
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/home',
    children: [{
      path: '/home',
      name: 'Home',
      component: () => import('@/views/home/index'),
      meta: {
        title: '主页',
        icon: '主页'
      }
    }]
  },

  {
    path: "/product",
    name: "Product",
    redirect: "/product/productList",
    component: Layout,
    meta: {
      title: '商品管理',
      icon: '商品'
    },
    children: [{
        path: "productList",
        name: "ProductProductList",
        component: () => import("@/views/product/productList"),
        meta: {
          title: '商品列表',
          icon: '商品列表'
        },
      },
      {
        path: "editProduct",
        name: "ProductEditProduct",
        hidden:true,
        component: () => import("@/views/product/productList/editProduct"),
        meta: {
          title: '商品编辑',
          icon: '商品编辑',
          activeMenu:"/product/productList"
        },
      },
      {
        path: "produceClassify",
        name: "productProduceClassify",
        component: () => import("@/views/product/produceClassify"),
        meta: {
          title: '商品分类',
          icon: '商品分类'
        },
      },
      {
        path: "brand",
        name: "productBrand",
        component: () => import("@/views/product/brand"),
        meta: {
          title: '品牌管理',
          icon: '品牌管理'
        },
      }
    ]
  },
  {
    path: "/permissions",
    name: "Permissions",
    redirect: "/permissions/account",
    component: Layout,
    meta: {
      title: '权限管理',
      icon: '权限管理'
    },
    children: [{
        path: "account",
        name: "PermissionsAccount",
        component: () => import("@/views/permissions/account"),
        meta: {
          title: '账号管理',
          icon: '账号管理'
        },
      },
      {
        path: "role",
        name: "PermissionsRole",
        component: () => import("@/views/permissions/role"),
        meta: {
          title: '角色管理',
          icon: '角色管理'
        },
      },
      {
        path: "resources",
        name: "PermissionsResources",
        component: () => import("@/views/permissions/resources"),
        meta: {
          title: '资源管理',
          icon: '资源管理'
        },
      }
    ]
  },
  {
    path: "/order",
    name: "Order",
    redirect: "/order/orderList",
    component: Layout,
    meta: {
      title: '订单管理',
      icon: 'orderLi'
    },
    children: [{
        path: "orderList",
        name: "OrderOrderList",
        component: () => import("@/views/order/orderList"),
        meta: {
          title: '订单列表',
          icon: '订单列表'
        },
      },
      {
        path: "orderDetail",
        name: "OrderOrderDetail",
        hidden: true,
        component: () => import("@/views/order/orderList/orderDetail"),
        meta: {
          title: '订单详情',
          icon: '订单详情',
          activeMenu: "/order/orderList"
        }
      },
      {
        path: "backOrder",
        name: "OrderBackOrder",
        component: () => import("@/views/order/backOrder"),
        meta: {
          title: '退单列表',
          icon: '退单'
        },
      },
      {
        path: "backOrderDetail",
        name: "OrderBackOrderBackOrderDetail",
        hidden: true,
        component: () => import("@/views/order/backOrder/backOrderDetail"),
        meta: {
          title: '退单详情',
          icon: '退单详情',
          activeMenu: "/order/backOrder"
        }
      },
      {
        path: "orderAddress",
        name: "OrderAddress",
        component: () => import("@/views/order/orderAddress"),
        meta: {
          title: '地址管理',
          icon: 'dizhi'
        },
      }
    ]
  },
  {
    path: "/registered",
    name: "Registered",
    alwaysShow: true,
    component: Layout,
    meta: {
      title: "注册用户管理",
      icon: "注册"
    },
    children: [{
        path: "user",
        name: "RegisteredUser",
        component: () => import("@/views/registered/user"),
        meta: {
          title: '用户列表',
          icon: '用户'
        },
      },

    ]
  },
  {
    path: '/content',
    name: "Content",
    redirect: '/content/article',
    component: Layout,
    meta: {
      title: '内容管理',
      icon: '内容'
    },
    children: [{
        path: 'article',
        name: 'ContentArticle',
        component: () => import('@/views/content/article'),
        meta: {
          title: '文章列表',
          icon: 'table'
        },
      },
      {
        path: 'material',
        name: 'ContentMaterial',
        component: () => import('@/views/content/material'),
        meta: {
          title: '素材管理',
          icon: 'tree'
        }
      },
      {
        path: "editArticle",
        name: "ContentEditArticle",
        component: () => import('@/views/content/editArticle'),
        hidden: true,
        meta: {
          title: '编辑列表',
          icon: 'table',
          activeMenu: '/content/article'
        },
      }

    ]
  },

  {
    path: "/marketing",
    name: "Marketing",
    redirect: "/marketing/activity",
    component: Layout,
    meta: {
      title: '营销管理',
      icon: '营销'
    },
    children: [{
        path: "activity",
        name: "MarketingActivity",
        component: () => import("@/views/marketing/activity"),
        meta: {
          title: '限时活动',
          icon: '限时抢购'
        },
      },
      {
        path: "banner",
        name: "MarketingBanner",
        component: () => import("@/views/marketing/banner"),
        meta: {
          title: '广告列表',
          icon: '广告'
        },
      }
    ]
  },
  {
    path: "/address",
    name: "Address",
    alwaysShow: true,
    component: Layout,
    meta: {
      title: "地址管理",
      icon: "地址"
    },
    children: [{
        path: "addressList",
        name: "AddressAddressList",
        component: () => import("@/views/address/addressList"),
        meta: {
          title: '地址列表',
          icon: 'dizhi'
        },
      },

    ]
  },

  // 404 page must be placed at the end !!!
  {
    path: '*',
    redirect: '/404',
    hidden: true
  }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({
    y: 0
  }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router

